package qc.module.sl.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import qc.module.sl.entity.SlBasicStationRelation;
import qc.module.sl.repository.SlBasicStarionRelationRepository;

import java.util.ArrayList;
import java.util.List;

/**
 * BasicStationRelationService
 *
 * @author QuCheng Tech
 * @create 2023/02/15
 */
@Service
public class BasicStationRelationService {
    private SlBasicStarionRelationRepository repository;
    
    @Autowired
    public void setSlBasicStationRelationRepository(SlBasicStarionRelationRepository repository){
        this.repository = repository;
    }
    
    /**
     * 根据分类编码查询站点编码
     * 
     * @param	classifycode	分类编码
     * @return 站点编码集合
     * @author QcCheng Tech
     * @since 2023/2/15
     */
    public List<String> queryStcdByClassifyCode(String classifycode){
        if (!StringUtils.isBlank(classifycode)){
            LambdaQueryWrapper<SlBasicStationRelation> wrapper = new LambdaQueryWrapper<>();

            wrapper.select(SlBasicStationRelation::getStcd);
            
            wrapper.eq(SlBasicStationRelation::getClassifycode, classifycode);
            
            List<SlBasicStationRelation> list = repository.selectList(wrapper);
            
            if (list.size() > 0x0){
                List<String> result = new ArrayList<>();
                for (int i = 0; i < list.size(); i++) {
                    result.add(list.get(i).getStcd());
                }
                return result;
            }
        }
        
        return null;
    }
}
